package com.ssm.opa.common.base.exception;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;

/**
 * <p/>
 * Copyright: Copyright (c) 2016/12/6
 * <p/>
 * Company: 途牛科技有限公司华东分公司
 * <p/>
 *
 * @author wanghongqi@tuniu.com
 * @version 1.0.0
 * @project gtb-parent
 */
public class TnException extends Exception {
	private int errorCode;
	private Object data;

	public TnException(int errorCode) {
		this.errorCode = errorCode;
	}

	public TnException(String message, int errorCode) {
		super(message);
		this.errorCode = errorCode;
	}

	public TnException(String message, Throwable cause, int errorCode) {
		super(message, cause);
		this.errorCode = errorCode;
	}

	public TnException(Throwable cause, int errorCode) {
		super(cause);
		this.errorCode = errorCode;
	}

	public TnException(TnException tnException) {
		this(tnException.getMessage(), tnException.getErrorCode());
	}

	public TnException(TnException tnException, String message) {
		this(message + "\n" + tnException.getMessage(), tnException.errorCode);
	}

	public TnException(TnException tnException, Throwable e) {
		this(Arrays.toString(e.getStackTrace()) + "\n" + tnException.getMessage(), tnException.errorCode);
	}

	public TnException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, int errorCode) {
		super(message, cause, enableSuppression, writableStackTrace);
		this.errorCode = errorCode;
	}

	private String getStackTraceInfo(Throwable e) {

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		e.printStackTrace(new PrintStream(out));
		return out.toString();
	}

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
